from django.db import models


class BaseCodeModel(models.Model):
    class Meta:
        abstract = True
        managed = False
        app_label = 'gxdm_temp'

    value = models.CharField('代码', max_length=255, primary_key=True)
    label = models.CharField('标签', max_length=255)


class Department(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'dwbmdm'


class IdCardType(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'sfzjlxdm'


class PoliticsStatus(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'zzmmdm'


class StudentStatus(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'xsdqztdm'


class Pycc(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'pyccdm'


class Pyfs(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'pyfsdm'


class Zwlb(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'zwlbdm'


class Xzqy(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'xzqydm'

    code = models.CharField('省份代码', max_length=2)
    province = models.CharField('省份', max_length=32)


class Mz(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'mzdm'


class Xl(BaseCodeModel):
    class Meta(BaseCodeModel.Meta):
        db_table = 'xldm'


# 获取标准单位部门代码列表
def get_department_list():
    department_choice = []
    for item in Department.objects.all():
        department_choice.append((item.value, item.label))
    return department_choice


# 获取院系代码列表
def get_faculty_list():
    faculty_choice = []
    for item in Department.objects.filter(value__startswith='2').exclude(value='20000'):
        faculty_choice.append((item.value, item.label))
    return faculty_choice


# 获取班级代码列表
'''
def get_class_list():
    class_choice = []

    for item in Gxxx04.objects.all():
        class_choice.append((item.value, item.label))
    return class_choice


# 获取专业代码列表
def get_major_list():
    major_choice = []
    for item in Major.objects.all():
        major_choice.append((item.value, item.label))
    return major_choice
'''

# 获取标准身份证件类型代码列表
def get_id_card_type_list():
    id_card_type_choice = []
    for item in IdCardType.objects.all():
        id_card_type_choice.append((item.value, item.label))
    return id_card_type_choice


# 获取标准政治面貌列表
def get_politics_status_list():
    politics_status_choice = []
    for item in PoliticsStatus.objects.all():
        politics_status_choice.append((item.value, item.label))
    return politics_status_choice


# 获取学生当前状态代码
def get_student_status():
    student_status = []
    for item in StudentStatus.objects.all():
        student_status.append((item.value, item.label))
    return student_status


# 获取培养层次代码
def get_pycc():
    pycc_list = []
    for item in Pycc.objects.all():
        pycc_list.append((item.value, item.label))
    return pycc_list


# 获取培养方式代码
def get_pyfs():
    pyfs_list = []
    for item in Pyfs.objects.filter(value__endswith='0'):
        pyfs_list.append((item.value, item.label))
    return pyfs_list


def get_zwlb():
    zwlb_list = []
    for item in Zwlb.objects.all():
        zwlb_list.append((item.value, item.label))
    return zwlb_list


def get_xzqy():
    xzqy_list = []
    for item in Xzqy.objects.all():
        xzqy_list.append((item.value, item.province + item.label))
    return xzqy_list


def get_jg():
    province_list = []
    for item in Xzqy.objects.filter(value__endswith='0000'):
        province_list.append((item.code, item.province))
    return province_list


def get_mz():
    mz_list = []
    for item in Mz.objects.all():
        mz_list.append((item.value, item.label))
    return mz_list


def get_xl():
    xl_list = []
    for item in Xl.objects.all():
        xl_list.append((item.value, item.label))
    return xl_list


class Code:
    SEX_CHOICE = (
        ('1', '男'),
        ('2', '女'),
    )

    TEACHER_STATUS_CHOICE = [
        ('1', '在职'),
        ('2', '离校'),
        ('3', '退休'),
        ('4', '试用期'),
        ('5', '离岗')
    ]

    TEACHER_TYPE_CHOICE = (
        (1, '教职工'),
        (2, '员工'),
        (3, '部门'),
        (4,'外聘教师')
    )

    # 港澳台侨外码
    GATQWM_CHOICE = (
        ('01', '香港同胞'),
        ('02', '香港同胞亲属'),
        ('03', '澳门同胞'),
        ('04', '澳门同胞亲属'),
        ('05', '台湾同胞'),
        ('06', '台湾同胞亲属'),
        ('11', '华侨'),
        ('12', '侨眷'),
        ('13', '归侨'),
        ('14', '归侨子女'),
        ('21', '归国留学人员'),
        ('32', '非华裔中国人'),
        ('41', '外籍华裔人'),
        ('51', '外国人'),
        ('99', '其他'),
    )

    # 职称级别
    ZCJB_CHOICE = (
        ('01', '初级'),
        ('02', '中级'),
        ('03', '副高级'),
        ('04', '正高级')
    )

    ZJ_CHOICE = (
        ('01', '副科级'),
        ('02', '正科级'),
        ('03', '副处级'),
        ('04', '正处级'),
    )

    # 是否开通OA
    OPENOA_CHOICE = (
        ('1', '是'),
        ('0', '否'),
    )

    # 婚姻状况代码
    HYZKM_CHOICE = (
        ('10', '未婚'),
        ('20', '已婚'),
        ('21', '初婚'),
        ('22', '再婚'),
        ('23', '复婚'),
        ('30', '丧偶'),
        ('40', '离婚'),
        ('90', '未说明的婚姻状况'),
    )

    # 健康状况码
    JKZKM_CHOICE = (
        ('10','健康或良好'),
        ('20','一般或较弱'),
        ('30','有慢性病'),
        ('31','心血管病'),
        ('32','脑血管病'),
        ('33','慢性呼吸系统病'),
        ('34','慢性消化系统病'),
        ('35','慢性肾炎'),
        ('36','结核病'),
        ('37','糖尿病'),
        ('38','神经或精神疾病'),
        ('41','癌症'),
        ('49','其他慢性病'),
        ('60','残疾'),
        ('61','视力残疾'),
        ('62','听力残疾'),
        ('69','其他残疾'),
        ('67','多重残疾'),
        ('66','精神残疾'),
        ('63','言语残疾'),
        ('64','肢体残疾'),
        ('65','智力残疾'),
    )

    # 血型码
    BLOOD_TYPE_CHOICE = (
        ('0', '未知血型'),
        ('1', 'A 血型'),
        ('2', 'B 血型'),
        ('3', 'AB 血型'),
        ('4', 'O 血型'),
        ('5', 'RH 阳性血型'),
        ('6', 'RH 阴性血型'),
        ('7', 'HLA 血型'),
        ('8', '未定血型'),
        ('9', '其他血型'),
    )

    # 编制类别码
    BZLB_CHOICE = (
        ('10', '教学类'),
        ('20', '行政类'),
        ('30', '教辅类'),
        ('40', '工勤类'),
        ('50', '科研类'),
        ('60', '校办企业类'),
        ('70', '附设机构类'),
        ('99', '其他类'),
    )

    # 校区码
    CAMPUS_CHOICE = (
        ('1', '松山湖'),
        ('2', '莞城'),
    )

    # 教职工类别码
    JZGLBM_CHOICE = (
        ('01', '教学人员'),
        ('02', '教学辅助人员'),
        ('03', '教学科研人员'),
        ('04', '专职科研人员'),
        ('05', '学生思政工作人员'),
        ('06', '心理咨询教师'),
        ('07', '校外教师'),
        ('08', '后勤产业人员'),
        ('09', '管理人员'),
        ('10', '专职辅导员'),
        ('11', '高层次人才'),
    )

    # 学生类型码
    XSLBM_CHOICE = (
        ('421', '本科生'),
        ('422', '成教生'),
        ('431', '研究生'),
    )

    # 职务类型
    ZWLX_CHOICE = (
        ('01', '行政'),
        ('02', '党委')
    )

    # 任职角色
    JS_CHOICE = (
        ('01', '一把手'),
        ('02', '二把手')
    )

    # 更新模式
    UPDATE_MODE_CHOCIE = (
        ('01', '软更新'),
        ('02', '硬更新'),
    )

    # 单位码
    DEPARTMENT_CHOICE = get_department_list()
    # 院系码
    FACULTY_CHOICE = get_faculty_list()
    # 班级码
    # CLASS_CHOICE = get_class_list()
    # 专业码
    # MAJOR_CHOICE = get_major_list()
    # 身份证件类型码
    IDCARD_TYPE_CHOICE = get_id_card_type_list()
    # 政治面貌码
    POLITICS_STATUS_CHOICE = get_politics_status_list()
    # 学生当前状态码
    XSDQZTM_CHOICE = get_student_status()
    # 培养层次码
    PYCCM_CHOICE = get_pycc()
    # 培养方式码
    PYFSM_CHOICE = get_pyfs()
    # 职务类别码
    ZWLB_CHOICE = get_zwlb()
    # 行政区域码
    XZQY_CHOICE = get_xzqy()
    # 籍贯码
    JG_CHOICE = get_jg()
    # 民族码
    MZ_CHOICE = get_mz()
    # 学历码
    XL_CHOICE = get_xl()




